﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace WowRaidListTracker.DAL
{
    public class CharacterClass
    {
        public static List<CharacterClass> CharacterClassCollection = new List<CharacterClass>();
        public static Dictionary<string, CharacterClass> CharacterClassDictionary = new Dictionary<string, CharacterClass>();

        #region CharacterClass Properties

        private int mId;
        public int Id
        {
            get { return mId; }
            set { mId = value; }
        }

        private string mName;
        public string Name
        {
            get { return mName; }
            set { mName = value; }
        }

        private bool mIsTank;
        public bool IsTank
        {
            get { return mIsTank; }
        }

        private bool mIsMeleeDPS;
        public bool IsMeleeDPS
        {
            get { return mIsMeleeDPS; }
        }

        private bool mIsRangedDPS;
        public bool IsRangedDPS
        {
            get { return mIsRangedDPS; }
        }

        private bool mIsCasterDPS;
        public bool IsCasterDPS
        {
            get { return mIsCasterDPS; }
        }

        private bool mIsHealer;
        public bool IsHealer
        {
            get { return mIsHealer; }
        }

        #endregion

        public CharacterClass() { }

        public CharacterClass(DataRow dr)
        {
            mId = Convert.ToInt32(dr["CharacterClassId"]);
            mName = Convert.ToString(dr["CharacterClassName"]);
            mIsTank = Convert.ToBoolean(dr["CharacterClassIsTank"]);
            mIsMeleeDPS = Convert.ToBoolean(dr["CharacterClassIsMeleeDPS"]);
            mIsRangedDPS = Convert.ToBoolean(dr["CharacterClassIsRangedDPS"]);
            mIsCasterDPS = Convert.ToBoolean(dr["CharacterClassIsCasterDPS"]);
            mIsHealer = Convert.ToBoolean(dr["CharacterClassIsHealer"]);
        }

        public static void PopulateCharacterClassCollection(ListTrackerDal dal)
        {
            string sql = CRUDReader.Crud.get("CharacterClasses", CRUDReader.QUDType.Select);
            object executeResult = dal.Execute(sql, SQLiteQueryType.STANDARDQUERY);
            CharacterClassCollection.Add(new CharacterClass()
            {
                Id = -1,
                Name = "Select Class..."
            });
            if (typeof(DataTable) == executeResult.GetType())
            {
                DataTable result = executeResult as DataTable;
                foreach (DataRow dr in result.Rows)
                {
                    CharacterClass cc = new CharacterClass(dr);
                    CharacterClass.CharacterClassCollection.Add(cc);
                    CharacterClass.CharacterClassDictionary.Add(cc.Name, cc);
                }
            }
            else
            {
                throw new InvalidTypeException("The type returned by the ListTrackerDal.Execute method was not correct");
            }
        }
    }
}
